<?php
/**
 * CCodeForm class file.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

/**
 * CCodeForm represents the form for collecting code generation parameters.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @version $Id: CCodeForm.php 2799 2011-01-01 19:31:13Z qiang.xue $
 * @package system.gii
 * @since 1.1.2
 */
class CmsWidgetForm extends CActiveForm
{
    public $formParams;
    public $formLayoutParams;
    public $formContentTabTitle = 'Content';

    /**
     * Initializes the widget.
     * This renders the form open tag.
     */
    public function init()
    {
        parent::init();
        Yii::app()->controller->beginClip('formContent');
    }

    /**
     * Runs the widget.
     */
    public function run()
    {
        Yii::app()->controller->endClip();
        Yii::app()->controller->beginClip('widgetSettings');
        if (is_object($this->formParams)):
if(!empty($this->formParams->elements)){
    $group = '';
    foreach($this->formParams->elements as $name => $elm) {
        if ($group != $elm->param->setting_group) {
            $group = $elm->param->setting_group;
            echo "<div class=\"form-group-heading\">{$group}</div>";
        }
        echo $elm->render();
    }
}
endif;
Yii::app()->controller->endClip();
Yii::app()->controller->beginClip('widgetLayoutSettings');
if (is_object($this->formLayoutParams)):
if(!empty($this->formLayoutParams->elements)){
    $group = '';
    foreach($this->formLayoutParams->elements as $name => $elm) {
        if ($group != $elm->param->setting_group) {
            $group = $elm->param->setting_group;
            echo "<div class=\"form-group-heading\">{$group}</div>";
        }
        echo $elm->render();
    }
}
endif;
Yii::app()->controller->endClip();

Yii::app()->controller->widget('zii.widgets.jui.CJuiTabs', array(
        'id'=>'page-tabs',
        'tabs'=>array(
            $this->formContentTabTitle => Yii::app()->controller->Clips['formContent'],
            'Widget Settings' => Yii::app()->controller->Clips['widgetSettings'],
            'Widget Layout Settings' => Yii::app()->controller->Clips['widgetLayoutSettings']
        ),
        'options'=>array(
            'cache'=>true,
        )
    ));
?>
        <div class="row buttons">
            <?php echo CHtml::submitButton('Save'); ?>
        </div>
        <?php
        parent::run();
        Yii::app()->clientScript->registerScript('WidgetChangeLayout', "
$('#currentLayout').change(function(){
    $('#view').val('view');
    $(this).closest('form').
        append('<input type=\"hidden\" name=\"continue\" value=\"1\" />')
        .get(0).submit();
});
");
    }
}